package com.xkp.news.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ShowIndexHTMLServlet  extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");

        //获取登录失败提交参数

        String a=req.getParameter("a");

        String msg="";
        if(a!=null){

            if("1".equals(a)){
                msg="用户名不存在";
            }

            if("2".equals(a)){
                msg="密码错误";
            }
            if("3".equals(a)){
                msg="没有登录，请登录后访问";
            }
        }

        resp.getWriter().write("<!DOCTYPE html>\n" +
                "<html lang=\"en\">\n" +
                "<head>\n" +
                "    <meta charset=\"UTF-8\">\n" +
                "    <title>登录页面</title>\n" +
                "</head>\n" +
                "<body>\n" +
                " <div align=\"center\">\n" +
                "<!--表单提交的地址-->\n" +
                "      <form action=\"login\" method=\"get\">\n" +
                "          <p>\n" +
                "             账号： <input type=\"text\" name=\"userAcct\" />\n" +
                "          </p>\n" +
                "          <p>\n" +
                "              密码： <input type=\"password\" name=\"userPwd\" />\n" +
                "          </p>\n" +
                "          <p>\n" +
                "               <input type=\"submit\" value=\"登录\" />\n" +
                "          </p>\n" +
                "      </form>\n" +
                "<h4>"+msg+"</h4>"+
                " </div>\n" +
                "</body>\n" +
                "</html>");


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
